package fr.jade.fraclite;

import java.util.HashMap;
import java.util.Map;

import org.objectweb.fractal.api.factory.InstantiationException;

// This should be replaced by a configuration file
public class FracLiteConfig {

  protected static ItfDesc componentItf                  = new ItfDesc("component", "org.objectweb.fractal.api.Component");
  protected static ItfDesc typeFactoryItf                = new ItfDesc("type-factory", "org.objectweb.fractal.api.type.TypeFactory");
  protected static ItfDesc genericFactoryItf             = new ItfDesc("generic-factory", "org.objectweb.fractal.api.factory.GenericFactory");
  protected static ItfDesc genericAttributeControllerItf = new ItfDesc("generic-attribute-controller", "fr.jade.fraclite.api.control.GenericAttributeController");
  protected static ItfDesc lifecycleControllerItf        = new ItfDesc("lifecycle-controller", "org.objectweb.fractal.api.control.LifeCycleController");
  protected static ItfDesc bindingControllerItf          = new ItfDesc("binding-controller", "org.objectweb.fractal.api.control.BindingController");
  protected static ItfDesc contentControllerItf          = new ItfDesc("content-controller", "org.objectweb.fractal.api.control.ContentController");
  protected static ItfDesc nameControllerItf             = new ItfDesc("name-controller", "org.objectweb.fractal.api.control.NameController");
  protected static ItfDesc superControllerItf            = new ItfDesc("super-controller", "fr.jade.fraclite.api.control.SuperControllerNotifier");
  
  protected static final String primitiveLabel = "primitive";
  protected static Map<ItfDesc, String> primitive = new HashMap<ItfDesc, String>();
  
  protected static final String compositeLabel = "composite";
  protected static Map<ItfDesc, String> composite = new HashMap<ItfDesc, String>();
  
  protected static final String bootstrapLabel = "bootstrap";
  protected static Map<ItfDesc, String> bootstrap = new HashMap<ItfDesc, String>();
  
  static{
    bootstrap.put(nameControllerItf, "fr.jade.fraclite.control.name.BasicNameController");
    bootstrap.put(superControllerItf, "fr.jade.fraclite.control.content.BasicSuperController");
    bootstrap.put(lifecycleControllerItf, "fr.jade.fraclite.control.lifecycle.BasicLifeCycleController");
    bootstrap.put(genericAttributeControllerItf, "fr.jade.fraclite.control.attribute.BasicGenericAttributeController");
    bootstrap.put(contentControllerItf, "fr.jade.fraclite.control.content.BasicContentController");
    bootstrap.put(genericFactoryItf, "fr.jade.fraclite.factory.BasicGenericFactory");
    bootstrap.put(typeFactoryItf, "fr.jade.fraclite.type.BasicTypeFactory");
    
    primitive.put(nameControllerItf, "fr.jade.fraclite.control.name.BasicNameController");
    primitive.put(superControllerItf, "fr.jade.fraclite.control.content.BasicSuperController");
    primitive.put(bindingControllerItf, "fr.jade.fraclite.control.binding.BasicBindingController");
    primitive.put(lifecycleControllerItf, "fr.jade.fraclite.control.lifecycle.BasicLifeCycleController");
    primitive.put(genericAttributeControllerItf, "fr.jade.fraclite.control.attribute.BasicGenericAttributeController");
    
    composite.put(nameControllerItf, "fr.jade.fraclite.control.name.BasicNameController");
    composite.put(superControllerItf, "fr.jade.fraclite.control.content.BasicSuperController");
    composite.put(contentControllerItf, "fr.jade.fraclite.control.content.BasicContentController");
    composite.put(bindingControllerItf, "fr.jade.fraclite.control.binding.BasicBindingController");
    composite.put(lifecycleControllerItf, "fr.jade.fraclite.control.lifecycle.BasicLifeCycleController");
    composite.put(genericAttributeControllerItf, "fr.jade.fraclite.control.attribute.BasicGenericAttributeController");
  }
  
  public static Map<ItfDesc,String> getControllerDesc(String controllerDescLabel) throws InstantiationException{
    if(primitiveLabel.equals(controllerDescLabel)) return primitive;
    if(compositeLabel.equals(controllerDescLabel)) return composite;
    if(bootstrapLabel.equals(controllerDescLabel)) return bootstrap;
    throw new InstantiationException("Can't find controllerDescLabel: " + controllerDescLabel);
  }

  public static String getComponentInterfaceImpl() {
    return "fr.jade.fraclite.BasicComponent";
  }

}
